package com.twu.biblioteca;

import java.util.ArrayList;

public class Biblioteca {
    ArrayList<Book> books;
    ArrayList<Movie> movies;
    ArrayList<User> users;
    User currentUser;

    public Biblioteca() {
        books = new ArrayList<Book>();
        movies = new ArrayList<Movie>();
        users = new ArrayList<User>();
        books.add(new Book("0001", "thinking in java", 1));
        books.add(new Book("0002", "thinking in lisp", 2));
        books.add(new Book("0003", "thinking in Ruby", 3));
        movies.add(new Movie("0001", "Sholay", "1975", "Ramesh Sippy"));
        movies.add(new Movie("0002", "Sholay", "1976", "Ramesh Sippy"));
        movies.add(new Movie("0003", "Sholay", "1977", "Ramesh Sippy"));
        movies.add(new Movie("0004", "Sholay", "1978", "Ramesh Sippy"));
        movies.add(new Movie("0005", "Sholay", "1979", "Ramesh Sippy"));
        movies.add(new Movie("0006", "Sholay", "1980", "Ramesh Sippy"));
        movies.add(new Movie("0007", "Sholay", "1981", "Ramesh Sippy"));
        users.add(new User("111-1111", "111"));
    }

    public boolean signIn(String username, String password) {
        for (User user : users) {
            if (username.equals(user.getUsername()) && password.equals(user.getPassword())) {
                currentUser = user;
                return true;
            }
        }
        System.out.println("Wrong username or password !!");
        return false;
    }

    public void showBooksList() {
        for (Book book : books) System.out.println(book.getId() + " :\t" + book.getTitle() + "\t:\t" + book.getNum());
    }

    public void showMoviesList() {
        for (Movie movie : movies)
            System.out.println(movie.getId() + " :\t" + movie.getName() + "\t:\t" + movie.getYear() + "\t:\t" + movie.getDirector() + "\t:\t" + movie.getRating());
    }

    public void reserveBook(String id) {
        for (Book book : books) {
            if (id.equals(book.getId()) && book.isAvailable()) {
                book.reserved();
                System.out.println("Thank you!!Enjoy the book");
                return;
            }
        }
        System.out.println("This book is Not available !!");
    }

    public void checkMembership() {
        System.out.println(currentUser.getUserInfo());
    }
}